package com.wzy.activiti02;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;

import java.io.IOException;

/*
 * 单个流程的挂起和激活
 *
 */
public class SuspendProcessInstance2 {
    public static void main(String[] args) throws IOException {
        //1.得到processEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //2.得到RuntimeService
        RuntimeService runtimeService = processEngine.getRuntimeService();
        //3.查询流程定义的对象
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processDefinitionKey("holiday").singleResult();

        //4.得到当前流程定义的实例是否都为暂停状态
        boolean suspended = processInstance.isSuspended();
        String processInstanceId = processInstance.getId();

        if (suspended) {
            //说明是暂停就可以激活操作
            runtimeService.activateProcessInstanceById(processInstanceId);
            System.out.println("流程定义:" + processInstanceId + "激活");
        } else {
            runtimeService.suspendProcessInstanceById(processInstanceId);
            System.out.println("流程定义:" + processInstanceId + "挂起");
        }
    }
}
